//
// Basic output class to dump MC event informations
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

#include "DMLROutput.hh"
#include "TFile.h"
#include "TTree.h"

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <fstream>
#ifdef __MAKECINTxx__
#pragma link C++ class vector<float>+;
#endif
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DMLROutput::DMLROutput(string outname)
{
  file = new TFile(outname.c_str(), "RECREATE");
 
  file->SetCompressionLevel(1);

  Particlea= new TClonesArray("Particle");
  Alphaa = new TClonesArray("Particle");
  Neutrona = new TClonesArray("Particle");
  Argona   = new TClonesArray("Particle");
  Gammaa   = new TClonesArray("Particle");
  Electrona   = new TClonesArray("Particle");

  tree = new TTree("tree","DMatterdata");
  tree->Branch("EvNum",&EvNum,"EvNum/I");
  tree->Branch("nPhoton",&nPhoton,"nPhoton/I");

  tree->Branch("nJ1PMThits",&nJ1PMThits,"nJ1PMThits/I");
  tree->Branch("nJ2PMThits",&nJ2PMThits,"nJ2PMThits/I");
  tree->Branch("nJ3PMThits",&nJ3PMThits,"nJ3PMThits/I");
  tree->Branch("nJ4PMThits",&nJ4PMThits,"nJ4PMThits/I");
  tree->Branch("nJ5PMThits",&nJ5PMThits,"nJ5PMThits/I");
  tree->Branch("nJ6PMThits",&nJ6PMThits,"nJ6PMThits/I");

  tree->Branch("nM1PMThits",&nM1PMThits,"nM1PMThits/I");
  tree->Branch("nM2PMThits",&nM2PMThits,"nM2PMThits/I");

  tree->Branch("nvetoPMT1hits",&nvetoPMT1hits,"nvetoPMT1hits/I");
  tree->Branch("nvetoPMT2hits",&nvetoPMT2hits,"nvetoPMT2hits/I");
  tree->Branch("nvetoPMT3hits",&nvetoPMT3hits,"nvetoPMT3hits/I");
  tree->Branch("nvetoPMT4hits",&nvetoPMT4hits,"nvetoPMT4hits/I");
  tree->Branch("nvetoPMT5hits",&nvetoPMT5hits,"nvetoPMT5hits/I");
  tree->Branch("nvetoPMT6hits",&nvetoPMT6hits,"nvetoPMT6hits/I");
  tree->Branch("nvetoPMT7hits",&nvetoPMT7hits,"nvetoPMT7hits/I");
  tree->Branch("nvetoPMT8hits",&nvetoPMT8hits,"nvetoPMT8hits/I");

  tree->Branch("Particleb",&Particlea,256000,1);
  tree->Branch("Alphab", &Alphaa,256000,1);
  tree->Branch("Neutronb", &Neutrona,256000,1);
  tree->Branch("Argonb",   &Argona,256000,1);
  tree->Branch("Gammab",   &Gammaa,256000,1);
  tree->Branch("Electronb",&Electrona,256000,1);

}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DMLROutput::~DMLROutput()
{
  tree->Write();
  file->Close();
  delete file;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void DMLROutput::Fill()
{
  if (tree) tree->Fill();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void DMLROutput::Cd()
{
  if (file) file->cd();
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
